﻿using System;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using WaterCloud.Code;
using WaterCloud.Domain.RecruitmentManagement;
using WaterCloud.Service;
using Microsoft.AspNetCore.Authorization;
using WaterCloud.Service.RecruitmentManagement;
using WaterCloud.Service.SystemOrganize;
using WaterCloud.Domain.SystemManage;
using WaterCloud.Service.SystemManage;

namespace WaterCloud.Web.Areas.RecruitmentManagement.Controllers
{
    /// <summary>
    /// 创 建：超级管理员
    /// 日 期：2025-04-02 13:16
    /// 描 述：招聘计划控制器类
    /// </summary>
    [Area("RecruitmentManagement")]
    public class RecruitmentplanController :  BaseController
    {
        public RecruitmentplanService _service {get;set;}
        public OrganizeService _orgservice { get; set; }
        #region 获取数据
        [HttpGet]
        public virtual ActionResult AddForm()
        {
            return View();
        }
       
        
        public async Task<ActionResult> GetSelectJson()
        {
            var data = await _service.GetList();
            //默认三级区域
            data = data.Where(a => a.F_ReviewMark==true&&a.F_EnabledMark==false).ToList();
            
            return Content(data.ToJson());
        }

        [HandlerAjaxOnly]
        [IgnoreAntiforgeryToken]
        public async Task<ActionResult> GetGridJson(SoulPage<RecruitmentplanEntity> pagination, string keyword)
        {
            if (string.IsNullOrEmpty(pagination.field))
            {
                pagination.field = "F_Id";
                pagination.order = "desc";
            }
            var data = await _service.GetLookList(pagination,keyword);
        
            


            return Content(pagination.setData(data).ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public async Task<ActionResult> GetListJson(string keyword)
        {
            var data = await _service.GetList(keyword);
            return Content(data.ToJson());
        }

        [HttpGet]
        [AllowAnonymous]
        public async Task<ActionResult> GetFormJson(string keyValue)
        {
            var data = await _service.GetLookForm(keyValue);
            return Content(data.ToJson());
        }
        #endregion

        #region 提交数据
        [HttpPost]
        [AllowAnonymous]
        public async Task<ActionResult> SubmitForm(RecruitmentplanEntity entity, string keyValue)
        {
            try
            {
                await _service.SubmitForm(entity, keyValue);
                return await Success("操作成功。", "", keyValue);
            }
            catch (Exception ex)
            {
                return await Error(ex.Message, "", keyValue);
            }
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [HandlerAuthorize]
        public async Task<ActionResult> DeleteForm(string keyValue)
        {
            try
            {
                await _service.DeleteForm(keyValue);
                return await Success("操作成功。", "", keyValue, DbLogType.Delete);
            }
            catch (Exception ex)
            {
                return await Error(ex.Message, "", keyValue, DbLogType.Delete);
            }
        }
        [HttpPost]
       
        public async Task<ActionResult> CloseForm(string keyValue,bool b)
        {
            try
            {
                await _service.CloseForm(keyValue,b);
                return await Success("操作成功。", "", keyValue, DbLogType.Delete);
            }
            catch (Exception ex)
            {
                return await Error(ex.Message, "", keyValue, DbLogType.Delete);
            }
        }
        [HttpPost]
      
        public async Task<ActionResult> ReviewForm(string keyValue, bool b)
        {
            try
            {
                await _service.ReviewForm(keyValue,b);
                return await Success("操作成功。", "", keyValue, DbLogType.Delete);
            }
            catch (Exception ex)
            {
                return await Error(ex.Message, "", keyValue, DbLogType.Delete);
            }
        }
        #endregion
    }
}
